package com.souku.finance.application.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.souku.finance.application.R;
import com.souku.finance.application.bean.RegisterSucceedBean;
import com.souku.finance.application.utils.MyTextUtil;
import com.souku.finance.application.utils.StringUtil;
import com.souku.finance.application.utils.level.StringUtils;
import com.souku.finance.application.utils.level.UIUtils;

import java.util.List;

/**
 * Created by Administrator on 2017/5/25 0025.
 */

public class RegisterGiftAdapter extends BaseAdapter {

    private Context context;
    private List<RegisterSucceedBean.Gift> list;

    public RegisterGiftAdapter(Context context, List<RegisterSucceedBean.Gift> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        if (list.size() > 0) {
            return list.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        RegisterGiftHolder holder;

        if (view == null) {
            view = UIUtils.inflate(R.layout.item_register_gift);
            holder = new RegisterGiftHolder(view);
            view.setTag(holder);
        } else {
            holder = (RegisterGiftHolder) view.getTag();
        }

        RegisterSucceedBean.Gift gift = list.get(i);
        holder.tvPercent.setText(gift.getRate() + "%");
        holder.tvText.setText(gift.getName());
        holder.tvTime.setText(MyTextUtil.changeTimeFormat2(gift.getEndTime()));

        return view;
    }

    static class RegisterGiftHolder {

        TextView tvPercent;
        TextView tvText;
        TextView tvTime;

        public RegisterGiftHolder(View view) {
            tvPercent = (TextView) view.findViewById(R.id.tv_percent);
            tvText = (TextView) view.findViewById(R.id.tv_text);
            tvTime = (TextView) view.findViewById(R.id.tv_time);
        }

    }

}
